//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CModelLoader.cpp>
///	@path	~/src/scene/loader/
///	@date	2008/04/17
///	@desc	.

#include "config/config.h"

#include "graphics/xmodel/CBasicModel.h"

#include "scene/loader/CModelLoader.h"

namespace xeres {

	IMPL_IOBJECT_CLASS( CSimpleModelLoader );

	// CSimpleModelLoader
	CSimpleModelLoader::CSimpleModelLoader( void )
	{
		TRACE_INFO( _S("Created simple model loader...") );
	}
	// ~CSimpleModelLoader
	CSimpleModelLoader::~CSimpleModelLoader( void )
	{
	}

	// OnLoad
	RefPass<IModel> CSimpleModelLoader::OnLoad( RefWeak<IData> res , ResourceLoader& loader )
	{
		TRACK_FUNCTION_SCOPE();
		static const WString _geometry( _S("geometry") );

		RefPass<IData> geo_res = res->GetChild( _geometry );
		if( geo_res.IsNull() )
		{
			TRACE_ERROR( _S("CSimpleModelLoader::OnLoad: No geometry section defined.") );
			return NULL;
		}

		RefPass<IGeometry> geo = loader.LoadGeometry( RefWeak<IData>( geo_res ) );
		if( geo.IsNull() )
		{
			return NULL;
		}

		RefPass<CBasicModel> model = new CBasicModel;
		model->SetGeometry( RefWeak<IGeometry>( geo ) );
		return model;
	}

} // namespace xeres
